import { Context, h, Schema } from 'koishi'

export const name = 'awa-split-msg-element'

export interface Config { }

export const Config: Schema<Config> = Schema.object({})

export function apply(ctx: Context) {
  ctx.command("asm", "awa_split_message")
    .alias("awa_split_message")
    .action(async ({ session, options }) => {
      if (!session.quote) {
        session.send("pls quote a msg");
        return;
      }

      let msg = "";

      const elements = h.parse(session.quote.content);
      ctx.logger.info(elements);

      for (let i = 0; i < elements.length; i++) {
        msg += `-----seg no.${i}-----\n`;
        const e = elements[i];

        msg += `type = ${e.type}\n`;
        if (e.type === "text") {
          msg += `e.attrs.content = ${e.attrs.content}\n`;
        } else if (e.type === "mface") {
          msg += `e.attrs.summary = ${e.attrs.summary}\n`;
        } else if (e.type === "img") {
          msg += `e.attrs.file = ${e.attrs.file}\n`;
          msg += `e.attrs.summary = ${e.attrs.summary}\n`;
        } else if (e.type === "at") {
          msg += `e.attrs.ud = ${e.attrs.id}\n`;
          msg += `e.attr.name = ${e.attrs.name}\n`;
        }
        msg += `-----------------\n`;
      }

      msg += `elements[].length = ${elements.length}`

      await session.send(msg);


    })
}
